package com.matt.repository.photoAlbum;

import com.matt.domain.photoalbum.PhotoAlbumStatic;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface PhotoAlbumStaticRepository extends  JpaRepository<PhotoAlbumStatic, String> , JpaSpecificationExecutor<PhotoAlbumStatic> {

       PhotoAlbumStatic getFirstByAreaIdAndId(String areaId, String id);

       Page<PhotoAlbumStatic> findByChildrenIdAndAreaIdOrderByCreatedDesc(String childrenId, String areaId, Pageable pageable);

       @Query(value = "select * from tb_photo_album_static p " +
               "where (p.name like CONCAT('%', :keyword, '%') or p.areaName like CONCAT('%', :keyword, '%')) " +
               "and p.aid in :areaIds #{#pageable}", nativeQuery = true)
       Page<PhotoAlbumStatic> findByKeywordAndAreaIdInOrderByCreatedDesc(@Param("keyword") String keyword,
                                                                         @Param("areaIds") List<String> areaIds,
                                                                         Pageable pageable);

       Page<PhotoAlbumStatic> findByAreaIdInOrderByCreatedDesc(List<String> areaIds, Pageable pageable);
}
